package com.xm;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池测试类
 *
 * @author xiaoming
 * @date 2021-02-20 13:36
 */
public class ThreadPoolNameTest {
    public static void main(String[] args) {
        // 创建线程池
        // 1. ThreadPoolExecutor
        MyThreadFactory myThreadFactory = new MyThreadFactory();
        ThreadPoolExecutor p = new ThreadPoolExecutor(2, 1024, 1L,
                TimeUnit.SECONDS, new ArrayBlockingQueue(2), myThreadFactory);

        for (int i = 0; i < 15; i++) {
            p.execute(new MyTestRunnable());
        }

        if (p.isShutdown()) {
            System.out.println("Thread pool Shutdown");
        }
        if (p.isTerminated()) {
            System.out.println("Thread pool Termnated");
        }
        if (p.isTerminating()) {
            System.out.println("Thread pool Termnating");
        }
        p.shutdown();

        // TODO 监听线程池

        // 需要执行的任务数量
        p.getTaskCount();
        // 已完成的任务数量
        p.getCompletedTaskCount();
        p.getLargestPoolSize();
        p.getPoolSize();
        p.getActiveCount();


//        myThreadFactory.newThread(new MyTestRunnable())

        // Executors.defaultThreadFactory()
        // 2. Executors 提供的静态方法
        

    }
}

